<template>
<div id="header">
  <h1>我是Header，我要使用Store中的数据</h1>
  <div>
    <h4>Store中State的count为{{count}}</h4>
    <h4>Store中State的price为{{price}}</h4>
  </div>
  <div>
    <button @click="increment">累加</button>
    <button @click="decrement">累减</button>
    <button @click="incrementN({n:3})">累加3</button>
    <button @click="incrementWait">等2秒加</button>
    <button @click="decrementWait">等2秒减</button>
  </div>
</div>
</template>

<script>
import {mapState,mapMutations,mapActions} from 'vuex'
export default {
  name: "Header",
  mounted() {
    console.log(this)
    // console.log(mapActions(['incrementWait','decrementWait']))
  },
  computed:{
    // //扩展写法
    // count(){
    //   return this.$store.state.count
    // },
    // price(){
    //   return this.$store.state.price
    // }
    //调用store中分装的简写mapState
    ...mapState('count',['count','price','movieList'])
  },
  methods:{
  //  调用store中封装的简写mapMutations
    ...mapMutations('count',{
      increment:'increment',
      decrement:'decrement',
      incrementN:'incrementN'
    }),
    ...mapActions('count',['incrementWait','decrementWait'])
  }
}
</script>

<style scoped>
#header{
  margin: 20px auto;
  width: 800px;
  background-color: pink;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
</style>